﻿var isBound = false;
document.onmousedown = function () {
    if (event.button == 1) {
        isBound = true;
    } else {
        // isBound =false;
    }
}
document.onmouseup = function () {
    isBound = false;
}
//禁止选中
window.onscroll = function () { isBound = false; }
document.onselectstart = new Function("event.returnValue=false;");
document.onkeydown = new Function(
        "if((event.keyCode==116)||(event.ctrlKey && event.keyCode==82)){ event.keyCode=0; event.returnValue=false; document.getElementById('BtnSx').onclick();}")
document.onkeydown = new Function(
        "if((event.keyCode==112)){document.getElementById('BtnYd').onclick(); }if((event.keyCode==113)){document.getElementById('BtnYl').onclick(); }if((event.keyCode==114)){document.getElementById('BtnTp').onclick(); }")
//初始化页面
$(document).ready(function () {
    //左键菜单下载
    GetLeftMenu();
    if ($.cookie('Size') == null) {
        $.cookie('Size', '13', { expires: 30 });
        $.cookie('IsCow', '0');
        $.cookie('Point', '0');
    }
    $.cookie('SeatCode', ' ');
    $.cookie('SeatPrice', ' ');
    $.cookie('SeatColor', ' ');
    $.cookie('TicketName', ' ');
    GetSeatList();
    setInterval("GetSeatList();", 10000);
});
//刷新
function Reflsh() {
    $('#checkFlag').show();
    $('#txtSumPrice').val('0.0');
    $('#txtTicketCount').val('0');
    $.cookie('SeatCode', ' ');
    $.cookie('SeatPrice', ' ');
    $.cookie('SeatColor', ' ');
    $.cookie('TicketName', ' ');
    GetSeatList();
}
//添加客户关系
function AddCustomer() {
    if ($("#CustName").val() == "") { alert("请输入客户姓名！"); return false; }
    if ($("#Tel").val() == "") { alert("请输入客户手机号码！"); return false; }
    if (confirm("是否提交客户关系资料！")) {
        $("#btnCustSumt").attr("disabled", "disabled");
        var url = "AddCustom.axd?Name=" + $("#CustName").val()
    + "&Tel=" + $("#CustTel").val() + "&Address="
    + $("#CustAddress").val() + "&Unit=" + $("#CustUnit").val()
    + "&Remake=" + $("#CustRemake").val() + "&Time=" + new Date();
        $.ajax({
            type: "get",
            url: url,
            cache: false,
            success: function (Result) {
                alert("添加成功！");
                $("#btnCustSumt").removeAttr("disabled");
                $("#CustName").val("");
                $("#CustTel").val("");
                $("#CustAddress").val("");
                $("#CustUnit").val("");
                $("#CustRemake").val("");
            },
            error: function () {
                alert("操作失败,请重新操作！");
                $("#btnCustSumt").removeAttr("disabled");
                return;
            }
        });
    }
}
//票类信息
function TicketNameList() {
    var str = "";
    var SumCount = "";
    var SumCun = "";
    $.ajax({
        type: "get",
        url: "GetTicketName.axd?TitleCode="
        + escape($("#TitleCode").val()) + "&SubCode="
        + escape($("#SubCode").val()) + "&Time=" + new Date(),
        success: function (Result) {
            var arr = new Array();
            arr = eval(Result);
            str += "<table cellpadding=\"0\" cellspacing=\"0\" class=\"S_table\">";
            str += "<tr >";
            str += "<td class=\"S_Td\">票类</td>";
            str += "<td class=\"S_Td\">票价</td>";
            str += "<td class=\"S_Td\">余座</td>";
            str += "<td  >总座位数</td>";
            str += "</tr>";
            $.each(arr, function (i) {
                SumCount = Number(SumCount) + Number(arr[i].Count);
                SumCun = Number(SumCun) + Number(arr[i].SumCount);
                str += "<tr>";
                str += "<td class=\"S_Td S_T\">";
                str += "<div style=\"width:90px;\">";
                str += "<div style=\"background-color:" + arr[i].Color + "; width:17px; height:17px; float:left \">";
                str += "</div><div style=\"width:60px;text-align:left; float:left\">" + arr[i].Ticketname + "</div></div></td>";
                str += "<td class=\"S_Td S_T\">" + arr[i].Price + "</td>";
                str += "<td class=\"S_Td S_T\">" + arr[i].Count + "</td>";
                str += "<td class=\"S_T\">";
                str += arr[i].SumCount;
                str += "</td>";
                str += "</tr>";
            });
            str += "<tr >";
            str += "<td class=\"S_Td S_T\">总计</td>";
            str += "<td class=\"S_Td S_T\">-</td>";
            str += "<td class=\"S_Td S_T\">&nbsp;" + SumCount + "</td>";
            str += "<td class=\"S_T\">&nbsp;" + SumCun + "</td>";
            str += "</tr>";
            str += "</table>";
            document.getElementById('TicketNameInfo').innerHTML = str;
        },
        error: function () { document.getElementById('TicketNameInfo').innerHTML = "票类信息加载错误！"; },
        async: false
    });
}
//分区座位图信息
function GetSeatList() {
    var Size;
    var IsCow;
    var Point;
    if ($.cookie('Size') == null) {
        Size = 13;
    } else { Size = $.cookie('Size'); }
    if ($.cookie('IsCow') == null) {
        IsCow = 0;
    } else { IsCow = $.cookie('IsCow'); }
    if ($.cookie('Point') == null) {
        Point = 0;
    } else { Point = $.cookie('Point'); }
    $('#P1').show();
    TicketNameList();
    var url = 'GetSeatList.axd?TitleCode='
    + escape($("#TitleCode").val())
    + '&SubCode=' + escape($("#SubCode").val())
    + '&ThCode=' + escape($("#ThCode").val())
    + '&Size=' + Size
    + '&IsCow=' + IsCow
    + '&Point=' + Point + "&Time=" + new Date();
    $.ajax({
        type: "get",
        url: url,
        cache: false,
        success: function (Result) {
            document.getElementById('Seats').innerHTML = Result;
            $('p').hide();
        },
        error: function () {
            $("#Seats").html("<font size=4>数据读取错误，请稍后再试!</font>");
            $('p').hide();
            return;
        }
    });
}
//显示/隐藏票类信息
function ShowHideTicketInfo() {
    if ($("#TicketInfo").css("display") == "none") {
        $("#TicketInfo").css("display", "");
    } else {
        $("#TicketInfo").css("display", "none");
    }
}
//显示/隐藏座位号
function ShowHideCow() {
    if ($.cookie('IsCow') == '1') {
        $.cookie('IsCow', '0');
        Reflsh();
    } else {
        $.cookie('IsCow', '1');
        Reflsh();
    }
}
//左移
function ChangLeft() {
    if (Number($.cookie('Point')) >= 50) {
        $.cookie('Point', Number($.cookie('Point')) - 50, { expires: 30 });
        Reflsh();
    }
}
//右移
function ChangRight() {
    if (Number($.cookie('Point')) < 400) {
        $.cookie('Point', Number($.cookie('Point')) + 50, { expires: 30 });
        Reflsh();
    }
}
//放大
function ChangBig() {
    if (Number($.cookie('Size')) < 22) {
        $.cookie('Size', Number($.cookie('Size')) + 2, { expires: 30 });
        Reflsh();
    }
}
//缩小
function ChangSmall() {
    if (Number($.cookie('Size')) > 8) {
        $.cookie('Size', Number($.cookie('Size')) - 2, { expires: 30 });
        Reflsh();
    }
}
//选择分区
function SelectArea() {
    window.showModalDialog("JT_Area.aspx?TitleCode=" +
    $("#TitleCode").val() + "&ThCode=" + $("#ThCode").val() + "", "", "location:No;status:No;help:No;dialogWidth:900px;dialogHeight:500px;scroll:no");
}
//座位选择
function Choose(e) {
    var div = e;
    var bColor = div.style.background;
    var bID = div.id;
    var bMsg = div.Msg;
    var bName = div.name; // bColor != '#3f420f' &&
    if (bColor != '#676767' && bColor != '#a7900d' && bColor != '#992c0a') {
        if (Number($("#txtTicketCount").val()) < 40) {
            $.cookie('SeatCode', $.trim($.cookie('SeatCode')) + bID + '|');
            $.cookie('SeatColor', $.trim($.cookie('SeatColor')) + bColor + '|');
            $.cookie('SeatPrice', $.trim($.cookie('SeatPrice')) + bName + '|');
            $.cookie('TicketName', $.trim($.cookie('TicketName')) + bMsg + '|');
            $(div).css("background-color", "#992c0a");
            $('#txtTicketCount').val(Number($("#txtTicketCount").val()) + 1);
            $('#txtSumPrice').val(Number($("#txtSumPrice").val()) + Number(bName));
        }
    } else if (bColor == '#992c0a') {
        var CodeArr = $.cookie('SeatCode').split('|');
        var ColorArr = $.cookie('SeatColor').split('|');
        var TicketNameArr = $.cookie('TicketName').split('|');
        for (var i = 0; i < CodeArr.length; i++) {
            if ($.trim(CodeArr[i].replace('|', '')) == bID) {
                $(div).css("background-color", ColorArr[i]);
                ColorArr = ColorArr.del(i);
                TicketNameArr = TicketNameArr.del(i);
                break;
            }
        }
        $('#txtTicketCount').val(Number($("#txtTicketCount").val()) - 1);
        $('#txtSumPrice').val(Number($("#txtSumPrice").val()) - Number(div.name));
        $.cookie('SeatCode', $.trim($.cookie('SeatCode')).replace(bID + "|", $.trim(escape(""))));
        $.cookie('SeatPrice', $.trim($.cookie('SeatPrice')).replace(bName + "|", $.trim(escape(""))));
        $.cookie('SeatColor', ColorArr.join("|"));
        $.cookie('TicketName', TicketNameArr.join("|"));
    }
}
//删除数组指定项
Array.prototype.del = function (n) {
    if (n < 0)
        return this;
    else
        return this.slice(0, n).concat(this.slice(n + 1, this.length));
}
//判断是否可以自由打折。
function isZK() {
    if ($.cookie('SaleType') == "1002") {
        $("#t4").removeAttr("disabled");
    }
    if ($('#TaoCode').val() == '') {
        $('#t5').remove();
    } else {
        $('#t13').html("套票销售");
    }


}
//销售操作onclick='E.location.reload();'
$("#BtnSale").click(function () {
    if ($.cookie('SeatCode') == ' ' || $.cookie('SeatCode') == null) {
        alert("友情提示：请选择要销售的座位！");
    } else {

        isTao();
        $.dialog(750, 500, "<table id=\"TABLE1\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"750px\"><tr><td align=\"center\" bgcolor=\"#ffffff\" colspan=\"3\" height=\"25\" style=\"color:Red\"width=\"14%\"><strong>销售客户资料<\strong></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">姓 &nbsp; &nbsp; 名：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px;\"><input ID=\"t1\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系电话：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t2\"  style=\"width: 250px\"/></td> </tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系地址：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t3\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">单 &nbsp; &nbsp; 位：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t8\"  style=\"width: 250px\"/></td></tr><tr style=\"height: 20px;\"><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 20px; width: 118px;\">销售方式：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 20px\"><select id=\"PayType\" name=\"PayType\" class='select' style=\"height:20px;\"><option>现金</option><option>支票</option><option>POS机</option><option>汇款</option><option>欠款</option></select><input ID=\"t6\" type=\"radio\" name=\"b\"  checked=checked  style=\"width:14px;height:20px;\" value='1' />非套票销售<input ID=\"t5\" type=\"radio\" name=\"b\"  style=\"width:14px;height:20px;\" value='2'/><label id='t13'></label></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"width: 118px\">总 &nbsp; &nbsp; 计：</td><td align=\"left\" bgcolor=\"#f6f6f6\" height=\"25\" style=\"width: 482px\">实际总金额：<font  style=\"color:Red; font-size:22px; font-weight:bold\">" + escape($("#txtSumPrice").val()) + "</font>X自由折扣：<input ID=\"t4\" value=10 maxlength=3  onchange=\"zkchang()\" disabled=disabled  style=\"width: 60px\"/>%=实收总金额:<label id='t15' style=\"color:Red; font-size:22px; font-weight:bold\"></label>[数量：" + $("#txtTicketCount").val() + "]</td></tr><tr> <td align=\"left\" bgcolor=\"#f6f6f6\" colspan=\"2\" style=\"height: 200px\"><iframe frameborder=\"0\" height=\"100%\" scrolling=\"yes\" src=\"S_CheckList.aspx?SubCode=" + $("#SubCode").attr("value") + "&Titlecode=" + $("#TitleCode").attr("value") + "&Thcode=" + $("#ThCode").attr("value") + "&Taocode=" + $("#TaoCode").attr("value") + "&TaoCount=" + $("#TaoCount").attr("value") + "&flag=0 \" width=\"746px\" name='E'></iframe></td> </tr><tr> <td align=\"left\"   colspan=\"2\"><div  style=\" float:left; \">距离停止销售时间还有：</div><div id=\"time\" style=\"color:Green;font-size:16px;font-weight:bold; float:left; \">300</div>秒</td> </tr></table>", SaleTicket);
        //SaleTime();
        zkchang();
        isZK();
    }
});
//倒计时
function SaleTime() {
    setInterval("if (Number(document.getElementById('time').innerHTML) > 0) {document.getElementById('time').innerHTML = Number(document.getElementById('time').innerHTML) - 1;}else{ window.location.reload();}", 1000); 
}
function SaleTicket() {
    if ($.cookie('SeatCode') == ' ' || $.cookie('SeatCode') == null) {
        alert("友情提示：请选择要销售的座位！");
        return false;
    }
    if (isNaN($("#t4").attr("value")) && Number($("#t4").val()) > 10) {
        alert("友情提示：折扣格式错误！");
        return false;
    }
    var var_select = $('#PayType').get(0).selectedIndex;
    var var_name = $("input[name='b']:checked").val();
    var ResList = new Array();
    if (confirm('友情提示：确定要销售你所选座位！')) {
        var Url = "Sixid=" + $.cookie('SeatCode') + "&Zhekou=" + escape
   ($("#t4").val()) + "&SaleModel=" + escape(var_name) + "&UserName=" + escape($("#t1").val()) + "&UserTel=" + escape($("#t2").val()) + "&UserAddress=" + escape($("#t3").val()) + "&UnitCode=" + escape($("#t8").val()) + "&IsSend=1&PayModel=" + var_select + "&TaoCode=" + escape($("#TaoCode").val()) + "&SumAmt=" + $("#txtSumPrice").val() + "&ICCode=1&TitleCode=" + $("#TitleCode").val() + "&AreaCode=" + $("#SubCode").val() + "&Msg=1&Time=" + new Date().toString();
        $('#checkFlag').show();
        $.ajax({
            type: "get",
            url: "SaleTicket.axd",
            data: Url,
            success: function (Result) {
                switch (Result) {
                    case "0":
                        alert('你的账号还未登录，系统终止售票业务!');
                        break;
                    case "1":
                        alert('发票已经用完,系统终止售票业务!');
                        break;
                    case "2":
                        alert('销售错误,系统终止售票业务!');
                        break;
                    default:
                        try {
                            ResList = Result.toString().split('|');
                            if (ResList != null) {
                                for (var j = 0; j < ResList.length; j++) {
                                    document.all("form1").FastReport.ClearAllSqlCommand();
                                    document.all("form1").FastReport.CloseProc();
                                    document.all("form1").FastReport.AddSqlCommand(ResList[j]);
                                    var PrintTemplate = "";
                                    PrintTemplate = "C:\\BarCode\\BarCode.fr3";
                                    document.all("form1").FastReport.PrintReportEx(PrintTemplate, 0, 0);
                                }
                                alert('恭喜：销售成功!');
                            }
                        } catch (e) {
                        }
                        break;
                }
                Reflsh();
            },
            error: function (result) {
                alert("抱歉：数据读取错误,请稍后再试!");
                Reflsh();
                $('p').hide();
            }
        });
        //移除层
        $("#dialog_mask_bg").fadeOut("fast", function () { $(this).remove(); });
        $("#dialog_box").remove();
    }
}
//折扣判断
function zkchang() {
    if (Number($("#t4").val()) > 10 || isNaN($("#t4").val())
    || $("#t4").val() == "0" || $("#t4").val() == "00") {
        alert("折扣格式错误！");
        $('#t4').val("10");
        $('#t15').html(FloatMul($("#txtSumPrice").val(), FloatMul($("#t4").val(), 0.1)));
    }
    else {
        $('#t15').html(FloatMul($("#txtSumPrice").val(), FloatMul($("#t4").val(), 0.1)));
    }
}
//判断金额
function IsMoney(M) {
    var a = /^[0-9]*(\.[0-9]{1,2})?$/;
    if (a.test(M)) {
        return true;
    }
}
//判断是否为套票
function isTao() {

    var ret = null;
    $.ajax({
        type: "get",
        url: "TaoCheckHandler.axd",
        data: "TitleCode=" + escape($("#TitleCode").attr("value")) + "&NameList=" + escape($.cookie('TicketName')) + "&Time=" + new Date().toString(),
        success: function (msg) {
            if (msg == 'false') {
                $('#TaoCode').val('');
                $('#TaoCount').val('');
            } else {
                var arr = msg.split(',');

                $('#TaoCode').val(arr[0]);
                $('#TaoCount').val(arr[1]);
            }
        },
        error: function () {
            $('#t5').remove();
            $('#TaoCode').val('');
            $('#TaoCount').val('');
        },
        cach: false,
        async: false
    });
}
